home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / ddj1291.zip / UI_DB.ASC < prev   
Text File  |  1991-11-11  |  3KB  |  93 lines

  1. _LINKING USER INFTERFACE AND DATABASE OBJECTS_
  2. by Eng-Lee Kwang and Christopher Rosebrugh
  3.  
  4. EXAMPLE 1: 
  5.  
  6. (a) 
  7.  
  8.     /* message template description */
  9.     %func_template bool UI_DO_SOMETHING_M (
  10.         obj_id                            /* IN:  object pointer  */
  11.     );
  12.  
  13.    /* Object class message description mapping. It is NOT necessary to declare 
  14.      * parameters to message since they are already defined in template. */
  15.     %function[UI_DO_SOMETHING_M]  ui_Bag_do_something;
  16.  
  17. --------------------------------------------------------------------------
  18. (b)
  19.  
  20. /* These macros are used by the UI framework to pass messages to particular
  21. * objects without requiring explicit knowledge of the object classes.
  22. * The typedef and macros are AUTOMATICALLY generated from the message 
  23. * template description.  These macros, etc. are only used by framework. */
  24. #define UI_DO_SOMETHING_M_ID     1
  25. typedef void                     (*UI_DO_SOMETHING_M_fn_t)( obj_id  );
  26. #define UI_DO_SOMETHING_M(_ftbl) (*(UI_DO_SOMETHING_M_fn_t)_ftbl[UI_DO_SOMETHING_M_ID])
  27.  
  28. /* Messages are implemented as re-directed MACRO'ed functions through function 
  29.  * table. This typedef and define is AUTOMATICALLY generated from a high-level
  30.  * message description. */
  31.     typedef void  (*ui_Bag_do_something_fn_t)( obj_id  );
  32.     #define ui_Bag_do_something (*(ui_Bag_do_something_fn_t)bag_ftbl[1])
  33.  
  34. /* Message function table for object class Bag. This table is AUTOMATICALLY 
  35.  * generated from the high-level message description. */
  36.     void *bag_ftbl[19] = {
  37.         (void *)...,
  38.         (void *)_ui_Bag_do_something,
  39.         ...
  40.     };
  41.  
  42.  
  43. EXAMPLE 2:
  44.  
  45. (a)
  46.  
  47.     void _ui_Bag_do_something(
  48.         ui_Bag_t  *bag                  /* corresponds to an obj_id */
  49.         )
  50.     {
  51.         ....
  52.     }
  53.  
  54.  
  55. (b)
  56.  
  57. /* Implementation of messaging mechanism for sending message DO_SOMETHING */
  58.     bool ui_do_something(
  59.         obj_id    id, 
  60.         ...
  61.         )
  62.     {
  63.         void  **ftbl;
  64.     
  65.         /* look for message function table associated with the object ID. */
  66.         ftbl = __find_object_ftbl(id);
  67.         if (ftbl && &UI_DO_SOMETHING_M(ftbl)) {
  68.            /* If function table exists for the object -> known object type
  69.             * and message DO_SOMETHING is defined, pass the message to the
  70.             * object (call the function!!) */
  71.            return UI_DO_SOMETHING_M(ftbl)(id, ...);
  72.         }
  73.         return FALSE;
  74.     }
  75.  
  76.  
  77.  
  78. EXAMPLE 3:
  79.  
  80.    db_handle = db_Int16_new(123);
  81.  
  82.    viewer_1 = ui_Num_new(...);
  83.  
  84.    viewer_2 = ui_Gauge_new(...);
  85.  
  86.    ui_attach_data(viewer_1, db_handle);
  87.  
  88.    ui_attach_data(viewer_2, db_handle);
  89.  
  90.  
  91.  
  92.  
  93.